/*

This file is part of Rooms3D.

Copyright (C) 2008 Pixecur Technologies Incorporated (Esotera).
Visit Esotera at http://www.esoteras3.com
 
Rooms3D is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
 
Rooms3D is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.
 
You should have received a copy of the GNU General Public License
along with Rooms3D; see the file COPYING.  If not, write to 
Pixecur Technologies, 213-31 Peet Street, St. John's, NL, A1B 3W8. 
 
Linking this library statically or dynamically with other modules is
making a combined work based on this library.  Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
 
*/

package com.datasentinel.j3d.controls;

import java.awt.AWTEvent;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

import javax.media.j3d.BranchGroup;
import javax.media.j3d.Canvas3D;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import com.sun.j3d.utils.universe.SimpleUniverse;


public abstract class J3DComponent extends BranchGroup
{
	protected Canvas3D canvas3D;
	protected SimpleUniverse universe;
	
	/**
	 * Component representation in Java3D scene graph
	 */
	protected J3DComponentUI ui;
	
    /** 
     * The button model's <code>changeListener</code>.
     */
    protected EventHandler changeListener = new EventHandler();
	
    
	public J3DComponent(Canvas3D canvas3D, SimpleUniverse universe)
	{
		this.canvas3D = canvas3D;
		this.universe = universe;
		
		setCapability(ALLOW_DETACH);
		
		initializeEventListeners();
		this.ui = createComponentUI();
		initializeComponent();
		renderComponent();
	}
    
    
	public Canvas3D getCanvas3D()
	{
		return canvas3D;
	}
    
    
	public void renderComponent()
	{
		ui.render3DComponentUI(this);
	}
    
	protected abstract J3DComponentUI createComponentUI();
	
	protected void initializeComponent()
	{
		
	}
	
	protected void initializeEventListeners()
	{
		
	}
	
    public void dispatchEvent(AWTEvent e) 
    {

    }
	
    /**
     * 
     */
    
    class EventHandler implements ActionListener, ChangeListener, ItemListener, ComponentListener{


		@Override
		public void actionPerformed(ActionEvent e)
		{
			
		}

		@Override
		public void stateChanged(ChangeEvent e)
		{
			renderComponent();
		}

		@Override
		public void itemStateChanged(ItemEvent e)
		{
			
		}

		@Override
		public void componentHidden(ComponentEvent e)
		{
			
		}

		@Override
		public void componentMoved(ComponentEvent e)
		{
			
		}

		@Override
		public void componentResized(ComponentEvent e)
		{
			renderComponent();
		}

		@Override
		public void componentShown(ComponentEvent e)
		{
			
		}
    	
    }
    
	
}
